#include <iostream>

using namespace std;

const int N = 5050;
string s, t;
int f[N][N];
int main()
{
	while (cin >> s >> t)
	{
		int n = s.size(), m = t.size();
		s = ' ' + s, t = ' ' + t;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				if (s[i] == t[j]) f[i][j] = f[i - 1][j - 1] + 1;
				else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
			}
		}
		cout << f[n][m] << endl;
	}

	
	return 0;
}